package Util;

import Entity.Course;
import Entity.CoursePlus;
import Entity.Student;
import Entity.StudentCourse;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/*
负责解析数据库操作的一些信息 如解析数量 解析课程
 */
public class SQLParse {

    public static int parseCount(ResultSet rs){
        try {
            if (rs.next()){
                int count = rs.getInt(1);
                return  count;
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  0;
    }

    public static List<CoursePlus> parseToCoursePlus(ResultSet rs){
        List<CoursePlus> courseList = new ArrayList<>();
        try {
            while (rs.next()) {
                CoursePlus course = new CoursePlus();

                String courseId = rs.getString("courseId");
                String courseName = rs.getString("courseName");
                String courseType = rs.getString("courseType");
                float courseCredit = rs.getFloat("courseCredit");
                int courseHour = rs.getInt("courseHour");
                int courseVolume = rs.getInt("courseVolume");
                String teacherId = rs.getString("teacherId");
                String courseDesc = rs.getString("courseDesc");
                int status = rs.getInt("status");
                float score = rs.getFloat("score");
                String teacherName = rs.getString("teacherName");

                course.setCourseId(courseId);
                course.setCourseName(courseName);
                course.setCourseType(courseType);
                course.setCourseCredit(courseCredit);
                course.setCourseHour(courseHour);
                course.setCourseVolume(courseVolume);
                course.setTeacherId(teacherId);
                course.setCourseDesc(courseDesc);
                course.setStatus(status);
                course.setScore(score);
                course.setTeacherName(teacherName);

                courseList.add(course);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return courseList;
    }



    public static List<Course> parseToCourse(ResultSet rs){
        List<Course> courseList = new ArrayList<>();
        try {
            while (rs.next()) {
                Course course = new Course();

                String courseId = rs.getString("courseId");
                String courseName = rs.getString("courseName");
                String courseType = rs.getString("courseType");
                float courseCredit = rs.getFloat("courseCredit");
                int courseHour = rs.getInt("courseHour");
                int courseVolume = rs.getInt("courseVolume");
                String teacherId = rs.getString("teacherId");
                String courseDesc = rs.getString("courseDesc");
                int status = rs.getInt("status");

                course.setCourseId(courseId);
                course.setCourseName(courseName);
                course.setCourseType(courseType);
                course.setCourseCredit(courseCredit);
                course.setCourseHour(courseHour);
                course.setCourseVolume(courseVolume);
                course.setTeacherId(teacherId);
                course.setCourseDesc(courseDesc);
                course.setStatus(status);


                courseList.add(course);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return courseList;
    }












    public static List<StudentCourse> parseToStudentCourse(ResultSet rs){
        List<StudentCourse> courseList = new ArrayList<>();
        try {
            while (rs.next()) {
                StudentCourse studentCourse = new StudentCourse();

                String courseId = rs.getString("courseId");
                String courseName = rs.getString("courseName");
                String courseType = rs.getString("courseType");
                float courseCredit = rs.getFloat("courseCredit");
                int courseHour = rs.getInt("courseHour");
                int courseVolume = rs.getInt("courseVolume");
                String teacherId = rs.getString("teacherId");
                String courseDesc = rs.getString("courseDesc");
                int status = rs.getInt("status");
                String studentId = rs.getString("studentId");
                String studentName = rs.getString("studentName");
                float score = rs.getFloat("score");


                studentCourse.setCourseId(courseId);
                studentCourse.setCourseName(courseName);
                studentCourse.setCourseType(courseType);
                studentCourse.setCourseCredit(courseCredit);
                studentCourse.setCourseHour(courseHour);
                studentCourse.setCourseVolume(courseVolume);
                studentCourse.setTeacherId(teacherId);
                studentCourse.setCourseDesc(courseDesc);
                studentCourse.setStatus(status);
                studentCourse.setStudentId(studentId);
                studentCourse.setStudentName(studentName);
                studentCourse.setScore(score);

                courseList.add(studentCourse);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return courseList;
    }



}
